home *** CD-ROM | disk | FTP | other *** search
/ Pesquisa Dirigida / Pesquisa Dirigida.iso / JOGOS / matrix_beta.swf / scripts / FCheckBoxSymbol.as next >
Text File  |  2005-01-07  |  8KB  |  321 lines

  1. function FCheckBoxClass()
  2. {
  3.    this.init();
  4. }
  5. FCheckBoxClass.prototype = new FUIComponentClass();
  6. Object.registerClass("FCheckBoxSymbol",FCheckBoxClass);
  7. FCheckBoxClass.prototype.init = function()
  8. {
  9.    super.setSize(this._width,this._height);
  10.    this.boundingBox_mc.unloadMovie();
  11.    this.attachMovie("fcb_hitArea","fcb_hitArea_mc",1);
  12.    this.attachMovie("fcb_states","fcb_states_mc",2);
  13.    this.attachMovie("FLabelSymbol","fLabel_mc",3);
  14.    super.init();
  15.    this.setChangeHandler(this.changeHandler);
  16.    this._xscale = 100;
  17.    this._yscale = 100;
  18.    this.setSize(this.width,this.height);
  19.    if(this.initialValue == undefined)
  20.    {
  21.       this.setCheckState(false);
  22.    }
  23.    else
  24.    {
  25.       this.setCheckState(this.initialValue);
  26.    }
  27.    if(this.label != undefined)
  28.    {
  29.       this.setLabel(this.label);
  30.    }
  31.    this.ROLE_SYSTEM_CHECKBUTTON = 44;
  32.    this.STATE_SYSTEM_CHECKED = 16;
  33.    this.EVENT_OBJECT_STATECHANGE = 32778;
  34.    this.EVENT_OBJECT_NAMECHANGE = 32780;
  35.    this._accImpl.master = this;
  36.    this._accImpl.stub = false;
  37.    this._accImpl.get_accRole = this.get_accRole;
  38.    this._accImpl.get_accName = this.get_accName;
  39.    this._accImpl.get_accState = this.get_accState;
  40.    this._accImpl.get_accDefaultAction = this.get_accDefaultAction;
  41.    this._accImpl.accDoDefaultAction = this.accDoDefaultAction;
  42. };
  43. FCheckBoxClass.prototype.setLabelPlacement = function(pos)
  44. {
  45.    this.setLabel(this.getLabel());
  46.    this.txtFormat(pos);
  47.    var halfLabelH = this.fLabel_mc._height / 2;
  48.    var halfFrameH = this.fcb_states_mc._height / 2;
  49.    var vertCenter = halfFrameH - halfLabelH;
  50.    var checkWidth = this.fcb_states_mc._width;
  51.    var frame = this.fcb_states_mc;
  52.    var label = this.fLabel_mc;
  53.    var w = 0;
  54.    if(frame._width > this.width)
  55.    {
  56.       w = 0;
  57.    }
  58.    else
  59.    {
  60.       w = this.width - frame._width;
  61.    }
  62.    this.fLabel_mc.setSize(w);
  63.    if(pos == "right" || pos == undefined)
  64.    {
  65.       this.labelPlacement = "right";
  66.       this.fcb_states_mc._x = 0;
  67.       this.fLabel_mc._x = checkWidth;
  68.       this.txtFormat("left");
  69.    }
  70.    else if(pos == "left")
  71.    {
  72.       this.labelPlacement = "left";
  73.       this.fLabel_mc._x = 0;
  74.       this.fcb_states_mc._x = this.width - checkWidth;
  75.       this.txtFormat("right");
  76.    }
  77.    this.fLabel_mc._y = vertCenter;
  78.    this.fcb_hitArea_mc._y = vertCenter;
  79. };
  80. FCheckBoxClass.prototype.txtFormat = function(pos)
  81. {
  82.    var txtS = this.textStyle;
  83.    var sTbl = this.styleTable;
  84.    txtS.align = sTbl.textAlign.value != undefined ? undefined : (txtS.align = pos);
  85.    txtS.leftMargin = sTbl.textLeftMargin.value != undefined ? undefined : (txtS.leftMargin = 0);
  86.    txtS.rightMargin = sTbl.textRightMargin.value != undefined ? undefined : (txtS.rightMargin = 0);
  87.    if(this.flabel_mc._height > this.height)
  88.    {
  89.       super.setSize(this.width,this.flabel_mc._height);
  90.    }
  91.    else
  92.    {
  93.       super.setSize(this.width,this.height);
  94.    }
  95.    this.fLabel_mc.labelField.setTextFormat(this.textStyle);
  96.    this.setEnabled(this.enable);
  97. };
  98. FCheckBoxClass.prototype.setHitArea = function(w, h)
  99. {
  100.    var hit = this.fcb_hitArea_mc;
  101.    this.hitArea = hit;
  102.    if(this.fcb_states_mc._width > w)
  103.    {
  104.       hit._width = this.fcb_states_mc._width;
  105.    }
  106.    else
  107.    {
  108.       hit._width = w;
  109.    }
  110.    hit._visible = false;
  111.    if(arguments.length > 1)
  112.    {
  113.       hit._height = h;
  114.    }
  115. };
  116. FCheckBoxClass.prototype.setSize = function(w)
  117. {
  118.    this.setLabel(this.getLabel());
  119.    this.setLabelPlacement(this.labelPlacement);
  120.    if(this.fcb_states_mc._height < this.flabel_mc.labelField._height)
  121.    {
  122.       super.setSize(w,this.flabel_mc.labelField._height);
  123.    }
  124.    this.setHitArea(this.width,this.height);
  125.    this.setLabelPlacement(this.labelPlacement);
  126. };
  127. FCheckBoxClass.prototype.drawFocusRect = function()
  128. {
  129.    this.drawRect(-2,-2,this._width + 6,this._height - 1);
  130. };
  131. FCheckBoxClass.prototype.onPress = function()
  132. {
  133.    this.pressFocus();
  134.    _root.focusRect.removeMovieClip();
  135.    var states = this.fcb_states_mc;
  136.    if(this.getValue())
  137.    {
  138.       states.gotoAndStop("checkedPress");
  139.    }
  140.    else
  141.    {
  142.       states.gotoAndStop("press");
  143.    }
  144. };
  145. FCheckBoxClass.prototype.onRelease = function()
  146. {
  147.    this.fcb_states_mc.gotoAndStop("up");
  148.    this.setValue(!this.checked);
  149. };
  150. FCheckBoxClass.prototype.onReleaseOutside = function()
  151. {
  152.    var states = this.fcb_states_mc;
  153.    if(this.getValue())
  154.    {
  155.       states.gotoAndStop("checkedEnabled");
  156.    }
  157.    else
  158.    {
  159.       states.gotoAndStop("up");
  160.    }
  161. };
  162. FCheckBoxClass.prototype.onDragOut = function()
  163. {
  164.    var states = this.fcb_states_mc;
  165.    if(this.getValue())
  166.    {
  167.       states.gotoAndStop("checkedEnabled");
  168.    }
  169.    else
  170.    {
  171.       states.gotoAndStop("up");
  172.    }
  173. };
  174. FCheckBoxClass.prototype.onDragOver = function()
  175. {
  176.    var states = this.fcb_states_mc;
  177.    if(this.getValue())
  178.    {
  179.       states.gotoAndStop("checkedPress");
  180.    }
  181.    else
  182.    {
  183.       states.gotoAndStop("press");
  184.    }
  185. };
  186. FCheckBoxClass.prototype.setValue = function(checkedValue)
  187. {
  188.    if(checkedValue || checkedValue == undefined)
  189.    {
  190.       this.setCheckState(checkedValue);
  191.    }
  192.    else if(checkedValue == false)
  193.    {
  194.       this.setCheckState(checkedValue);
  195.    }
  196.    this.executeCallBack();
  197.    if(Accessibility.isActive())
  198.    {
  199.       Accessibility.sendEvent(this,0,this.EVENT_OBJECT_STATECHANGE,true);
  200.    }
  201. };
  202. FCheckBoxClass.prototype.setCheckState = function(checkedValue)
  203. {
  204.    var states = this.fcb_states_mc;
  205.    if(this.enable)
  206.    {
  207.       this.flabel_mc.setEnabled(true);
  208.       if(checkedValue || checkedValue == undefined)
  209.       {
  210.          states.gotoAndStop("checkedEnabled");
  211.          this.enabled = true;
  212.          this.checked = true;
  213.       }
  214.       else
  215.       {
  216.          states.gotoAndStop("up");
  217.          this.enabled = true;
  218.          this.checked = false;
  219.       }
  220.    }
  221.    else
  222.    {
  223.       this.flabel_mc.setEnabled(false);
  224.       if(checkedValue || checkedValue == undefined)
  225.       {
  226.          states.gotoAndStop("checkedDisabled");
  227.          this.enabled = false;
  228.          this.checked = true;
  229.       }
  230.       else
  231.       {
  232.          states.gotoAndStop("uncheckedDisabled");
  233.          this.enabled = false;
  234.          this.checked = false;
  235.          this.focusRect.removeMovieClip();
  236.       }
  237.    }
  238. };
  239. FCheckBoxClass.prototype.getValue = function()
  240. {
  241.    return this.checked;
  242. };
  243. FCheckBoxClass.prototype.setEnabled = function(enable)
  244. {
  245.    if(enable == true || enable == undefined)
  246.    {
  247.       this.enable = true;
  248.       Super.setEnabled(true);
  249.    }
  250.    else
  251.    {
  252.       this.enable = false;
  253.       Super.setEnabled(false);
  254.    }
  255.    this.setCheckState(this.checked);
  256. };
  257. FCheckBoxClass.prototype.getEnabled = function()
  258. {
  259.    return this.enable;
  260. };
  261. FCheckBoxClass.prototype.setLabel = function(label)
  262. {
  263.    this.fLabel_mc.setLabel(label);
  264.    this.txtFormat();
  265.    if(Accessibility.isActive())
  266.    {
  267.       Accessibility.sendEvent(this,0,this.EVENT_OBJECT_NAMECHANGE);
  268.    }
  269. };
  270. FCheckBoxClass.prototype.getLabel = function()
  271. {
  272.    return this.fLabel_mc.labelField.text;
  273. };
  274. FCheckBoxClass.prototype.setTextColor = function(color)
  275. {
  276.    this.fLabel_mc.labelField.textColor = color;
  277. };
  278. FCheckBoxClass.prototype.myOnKeyDown = function()
  279. {
  280.    if(Key.getCode() == 32 && this.pressOnce == undefined && this.enabled == true)
  281.    {
  282.       this.setValue(!this.getValue());
  283.       this.pressOnce = true;
  284.    }
  285. };
  286. FCheckBoxClass.prototype.myOnKeyUp = function()
  287. {
  288.    if(Key.getCode() == 32)
  289.    {
  290.       this.pressOnce = undefined;
  291.    }
  292. };
  293. FCheckBoxClass.prototype.get_accRole = function(childId)
  294. {
  295.    return this.master.ROLE_SYSTEM_CHECKBUTTON;
  296. };
  297. FCheckBoxClass.prototype.get_accName = function(childId)
  298. {
  299.    return this.master.getLabel();
  300. };
  301. FCheckBoxClass.prototype.get_accState = function(childId)
  302. {
  303.    if(this.master.getValue())
  304.    {
  305.       return this.master.STATE_SYSTEM_CHECKED;
  306.    }
  307.    return 0;
  308. };
  309. FCheckBoxClass.prototype.get_accDefaultAction = function(childId)
  310. {
  311.    if(this.master.getValue())
  312.    {
  313.       return "UnCheck";
  314.    }
  315.    return "Check";
  316. };
  317. FCheckBoxClass.prototype.accDoDefaultAction = function(childId)
  318. {
  319.    this.master.setValue(!this.master.getValue());
  320. };
  321.